import React from 'react';
import Utils from '../../../utils/utils'
import {fetch, post} from '../../../my_axios/api'
import {Card, Button, Table, Icon, Modal, message} from 'antd';
import PageTitle from '../../../components/PageTitle/index'
import BaseForm from '../../../components/BaseForm/index'
import SearchBar from '../../../components/search_bar/index'
import LTable from '../../../components/LTable/index'
export default class Workshop extends React.Component {
    state={
        formList:[
            {
                type: 'INPUT',
                label: '编号',
                field: 'code',
                placeholder: '请输入编号',
                initialValue:'',
                rule: true,
            },
            {
                type: 'INPUT',
                label: '名称',
                field: 'name',
                placeholder: '请输入名称',
                initialValue:'',
                rule: true,
            },
            {
                type: 'CHECKBOX',
                label: '是否小于',
                field: 'less_than',
                initialValue:false,
                rule: true,
            },
            {
                type: 'INPUTNUMBER',
                label: '值',
                field: 'less_number',
                placeholder: '请输入',
                initialValue:'',
                rule: true,
            },
        ],
        searchFormList: [
            {
                type: 'INPUT',
                label: '编号',
                field: 'code',
                placeholder: '请输入编号',
                initialValue: '',
                width: 220,
            },
            {
                type: 'INPUT',
                label: '名称',
                field: 'name',
                placeholder: '请输入名称',
                initialValue: '',
                width: 220,
            },
        ],
        buttonList: [
            {
                type: 'primary',
                icon: 'plus',
                isShow: false,
                name: '新增',
                methodName: 'add'
            },
            {
                type: 'primary',
                icon: 'edit',
                isShow: false,
                name: '修改',
                methodName: 'update'
            },
            {
                type: 'primary',
                icon: 'eye-o',
                isShow: false,
                name: '读取',
                methodName: 'look'
            },
            {
                type: 'danger',
                icon: 'delete',
                isShow: false,
                name: '删除',
                methodName: 'delete'
            },
        ],
        workshopList:[]
    };
    workshop='';
    componentWillMount() {
        this.getPermissionByPath();
    };
    /**
     * 根据权限获取按钮
     */
    getPermissionByPath() {
        let params = {
            route: '/collector/list'
        };
        fetch('permission/children', params).then(res => {
            if (res.status === 'success') {
                let list = this.state.buttonList;
                for (let permission of res.data) {
                    for (let button of list) {
                        if (permission.name === button.name) {
                            if (permission.name === '读取') {
                                button.name = '查看'
                            }
                            button.isShow = true;
                        }
                    }
                }
                this.setState({
                    buttonList: list
                })

            } else {
                message.error(res.data.message);
            }

        }).catch(err => {
            console.log(err);
        })
    }
    /**
     * 操作按钮
     */
    buttonMethods(name) {
        if (name !== 'add' && (this.workshop === '' || this.workshop === undefined)) {
            message.error('请选择管理器');
        } else {

        }
    }
    /**
     * 查询
     */
    filterSubmit = (fieldsValue) => {
        // this.setState(
        //     {
        //         pagination:{
        //             ...this.state.pagination,
        //             name:fieldsValue.name,
        //             code:fieldsValue.code,
        //             department:fieldsValue.department_id,
        //             current:1
        //         }
        //     },()=>{
        //         this.getCollectorList();
        //     }
        // )
    };
    render() {
        return (
            <div style={{padding: 10, background: 'white'}}>
                <PageTitle
                    title="车间管理"
                    buttonMethods={this.buttonMethods.bind(this)}
                    buttonList={this.state.buttonList}
                />
                <SearchBar
                    formList={this.state.searchFormList}
                    filterSubmit={this.filterSubmit}
                >
                </SearchBar>
                <LTable
                    setId={this.getId}
                    size='small'
                    loading={this.state.loading}
                    scroll={{x: 800}}
                    _this={this}
                    updateSelectedItem={Utils.updateSelectedItem.bind(this)}
                    selectedRowKeys={this.state.selectedRowKeys}
                    columns={columns}
                    selectedIds={this.state.selectedIds}
                    selectedItem={this.state.selectedItem}
                    dataSource={this.state.workshopList}
                    rowSelection={'radio'}
                    pagination={{  // 分页
                        pagination: true,
                        hideOnSinglePage: true,
                        ...this.state.pagination,
                        onChange: this.pageChange,
                    }}
                />
            </div>
        )
    };
}
const columns = [
    {
        title: '编号',
        dataIndex: 'code',
        key: 'code',
    }, {
        title: '名称',
        dataIndex: 'name',
        key: 'name',
    },{
        title: '是否小于',
        dataIndex: 'less_than',
        key: 'less_than',
    },{
        title: '值',
        dataIndex: 'less_number',
        key: 'less_number',
    },{
        title: '状态',
        dataIndex: 'status',
        key: 'status',
    }
];